package LeetCode;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}17:13
 */
public class E3 {//矩阵中是否存在指定的数
    static public void main(String[] args) {
        int[][] matrix = {{1,3}};
        System.out.println(findNumberIn2DArray(matrix,3));
    }
    public static boolean findNumberIn2DArray(int[][] matrix, int target) {
        boolean index = false;
        if (matrix == null || matrix.length == 0) {
            return index;
        }
        for (int i = 0; i < matrix.length; i++){
            if (matrix[i].length ==0){
                break;
            }
//            System.out.println(matrix[i][matrix.length-1]);
            if (matrix[i][matrix[i].length-1] < target || matrix[i][0] >target)
                continue;
            for (int j = 0; j < matrix[i].length;j++){
                if (matrix[i][j] == target){
                    index = true;
                    return index;
                }
            }
        }
        return index;
    }
}
